#include "timestamp.h"

#include <ctime>

Timestamp::Timestamp() : micro_seconds_since_epoch_(0) {}
Timestamp::Timestamp(int64_t micro_seconds_since_epoch)
    : micro_seconds_since_epoch_(micro_seconds_since_epoch) {}
Timestamp Timestamp::now() {
    return Timestamp(time(nullptr)); // time_t
}
std::string Timestamp::to_string() const {
    char buf[128] = {0};
    tm *tm_time = localtime(&micro_seconds_since_epoch_);
    snprintf(buf, 128,
             "%4d/%02d/%02d %02d:%02d:%02d", // 02d，右对齐补0，否则补空格，2位
             tm_time->tm_year + 1900, tm_time->tm_mon + 1, tm_time->tm_mday, tm_time->tm_hour,
             tm_time->tm_min, tm_time->tm_sec);
    return buf;
}